local wjsl_zhenfen = fk.CreateSkill {
  name = "wjsl_zhenfen",
  tags = { Skill.Compulsory, },
}


wjsl_zhenfen:addEffect(fk.TargetSpecifying, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(wjsl_zhenfen.name) then return end
    if player == target and data.card then
      if data.card.trueName == "slash" and player:getMark("@slash_dmg") > 0 then
        event:setCostData(self, "@slash_dmg")
        return true
      end
      if data.card.type == Card.TypeTrick and data.card.is_damage_card and player:getMark("@trick_dmg") > 0 then
        event:setCostData(self, "@trick_dmg")
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local mark = event:getCostData(self)
    data.additionalDamage = (data.additionalDamage or 0) + player:getMark(mark)
  end,
})

wjsl_zhenfen:addEffect(fk.DrawNCards, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(wjsl_zhenfen.name) then return end
    return player:getMark("@df_lingxin") > 0 and player == target
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n + player:getMark("@df_lingxin")
  end,
})

wjsl_zhenfen:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(wjsl_zhenfen.name) then return end
    return player:getMark("@shieldnum") > 0 and player:getMark("@shieldnum") - player.shield > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.shield = player:getMark("@shieldnum")
    room:broadcastProperty(player, "shield")
  end,
})

wjsl_zhenfen:addEffect("maxcards", {
  correct_func = function (self, player)
    if player:hasSkill("wjsl_zhenfen") and player:getMark("@df_lingxin") > 0 then
      return player:getMark("@df_lingxin")
    end
  end,
})

wjsl_zhenfen:addEffect("targetmod", {
  name = "#zhenfen_targetmod",
  residue_func = function(self, player, skill, scope)
    if player:hasSkill(wjsl_zhenfen.name) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase and player:getMark("@slash_num") > 0 then
      return player:getMark("@slash_num")
    end
  end,
})


return wjsl_zhenfen